//
//  ARResource.m
//  Staff
//
//  Created by Marcus on 12/28/14.
//
//

#import "ARResource.h"
#import "ARDatabase.h"
#import "ARVideo.h"

@implementation ARResource

+ (ARResource *)parserARResourcWithJson:(NSDictionary *)jsonDic {
    ARResource *arResource = [[ARResource alloc] init];
    NSMutableArray *videos = [[NSMutableArray alloc] init];
    
    if ([jsonDic objectForKey:@"database"]) {
        arResource.arDataBase = [ARDatabase parserARDatabaseObjectWithJson:[jsonDic objectForKey:@"database"]];
    }
    
    if ([[jsonDic objectForKey:@"video"] isKindOfClass:[NSDictionary class]]) {
        ARVideo *resource = [ARVideo parserARVideoObjectWithJson:[jsonDic objectForKey:@"video"]];
        [videos addObject:resource];
    } else if ([[jsonDic objectForKey:@"video"] isKindOfClass:[NSArray class]]) {
        for (NSDictionary *resDic in [jsonDic objectForKey:@"video"]) {
            ARVideo *resource = [ARVideo parserARVideoObjectWithJson:resDic];
            [videos addObject:resource];
        }
    }
    arResource.arVideos = videos;
    
    return arResource;
}

@end
